package com.github.shiqiyue.learn.guava;

import com.google.common.primitives.Booleans;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/***
 * 描述
 * @author wenyao.wu
 * @date 2018/7/3
 */
public class BooleansTest {

    private static final Logger logger = LoggerFactory.getLogger(BooleansTest.class);

    public static void main(String[] args) {
        /***
         * booleans
         */
        boolean[] booleanArray = {true, true, false, true, true, false, false};

        //convert array of primitives to array of objects
        List<Boolean> objectArray = Booleans.asList(booleanArray);
        logger.info("{}", objectArray);

        //convert array of objects to array of primitives
        booleanArray = Booleans.toArray(objectArray);

        logger.info("{}", booleanArray);
        //check if element is present in the list of primitives or not
        logger.info("true is in list? {}", Booleans.contains(booleanArray, true));

        //return the first index of element
        logger.info("true position in list {}", Booleans.indexOf(booleanArray, true));

        //Returns the count of true values	
        logger.info("true occured: {}", Booleans.countTrue());
        //Returns the comparisons
        logger.info("false Vs true: {}", Booleans.compare(false, true));
        logger.info("false Vs false: {}", Booleans.compare(false, false));
        logger.info("true Vs false: {}", Booleans.compare(true, false));
        logger.info("true Vs true: {}", Booleans.compare(true, true));
    }

}
